import { defineStore } from 'pinia';
import { getApiList } from '@/server/index';
import type { RootObject, ProvinceArrayList, CityArrayList, CityData, ChinaAdd, ChinaTotal } from "./type"
import { number } from 'echarts';

// ✅ 正确使用Pinia 2.x语法
export const useStore = defineStore('counter', {
  // 📌 State定义（推荐使用类型断言）
  state: () => ({
    list: {} as RootObject,
    name: "",
    date: "",
    total: 0,
    provinceArrayList: [] as ProvinceArrayList[],
    provinceArrayDetailList: [] as ProvinceArrayList[],
    provinceArrayDetailList2: [] as ProvinceArrayList[],
    CityArrayList: [] as CityArrayList[],
    CityData: {} as CityData,
    ChinaAdd: {} as ChinaAdd,
    ChinaTotal: {} as ChinaTotal,
    ChinaAddList: [] as number[],
  }),

  actions: {
    async getList() {
      const res: RootObject = await getApiList()
      this.provinceArrayList = res.provinceArrayList
      this.ChinaAdd = res.chinaAdd
      this.ChinaTotal = res.chinaTotal
      this.list = res
      this.provinceArrayDetailList = res.provinceArrayList.slice(6, 11)
      this.provinceArrayDetailList2 = res.provinceArrayList.slice(10, 19)
      // return res
    },

    async getDetail() {
      const res: RootObject = await getApiList()
      return res.provinceArrayList.slice(0, 5)
    }
  }

})